﻿using System;
using PairingMatrix.Common.Command;
using PairingMatrix.Services;

namespace PairingMatrix.Model
{
    public class SettingsModel : BusinessModelBase
    {
        private readonly PairingMatrixServiceClient _dataService;
        public SettingsModel(PairingMatrixServiceClient dataService)
        {
            _dataService = dataService;
            IterationEndDate = DateTime.Now;
        }


        private string _mingleUsername;
        public string MingleUsername
        {
            get { return _mingleUsername; }
            set
            {
                if (_mingleUsername == value)
                    return;
                _mingleUsername = value;
                OnPropertyChanged("MingleUsername");
            }
        }

        private string _minglePassword;
        public string MinglePassword
        {
            get { return _minglePassword; }
            set
            {
                if (_minglePassword == value)
                    return;
                _minglePassword = value;
                OnPropertyChanged("MinglePassword");
            }
        }

        private string _mingleStoryUrl;
        public string MingleStoryUrl
        {
            get { return _mingleStoryUrl; }
            set
            {
                if (_mingleStoryUrl == value)
                    return;
                _mingleStoryUrl = value;
                OnPropertyChanged("MingleStoryUrl");
            }
        }

        private bool _mingleStoryUrlBringAllCardsFromMingle;
        public bool MingleStoryUrlBringAllCardsFromMingle
        {
            get { return _mingleStoryUrlBringAllCardsFromMingle; }
            set
            {
                if (_mingleStoryUrlBringAllCardsFromMingle == value)
                    return;
                _mingleStoryUrlBringAllCardsFromMingle = value;
                OnPropertyChanged("MingleStoryUrlBringAllCardsFromMingle");
            }
        }

        private string _mingleRegressionUrl;
        public string MingleRegressionUrl
        {
            get { return _mingleRegressionUrl; }
            set
            {
                if (_mingleRegressionUrl == value)
                    return;
                _mingleRegressionUrl = value;
                OnPropertyChanged("MingleRegressionUrl");
            }
        }

        private bool _mingleRegressionUrlBringAllCardsFromMingle;
        public bool MingleRegressionUrlBringAllCardsFromMingle
        {
            get { return _mingleRegressionUrlBringAllCardsFromMingle; }
            set
            {
                if (_mingleRegressionUrlBringAllCardsFromMingle == value)
                    return;
                _mingleRegressionUrlBringAllCardsFromMingle = value;
                OnPropertyChanged("MingleRegressionUrlBringAllCardsFromMingle");
            }
        }

        private string _mingleDPSUrl;
        public string MingleDPSUrl
        {
            get { return _mingleDPSUrl; }
            set
            {
                if (_mingleDPSUrl == value)
                    return;
                _mingleDPSUrl = value;
                OnPropertyChanged("MingleDPSUrl");
            }
        }

        private bool _mingleDPSUrlBringAllCardsFromMingle;
        public bool MingleDPSUrlBringAllCardsFromMingle
        {
            get { return _mingleDPSUrlBringAllCardsFromMingle; }
            set
            {
                if (_mingleDPSUrlBringAllCardsFromMingle == value)
                    return;
                _mingleDPSUrlBringAllCardsFromMingle = value;
                OnPropertyChanged("MingleDPSUrlBringAllCardsFromMingle");
            }
        }

        private double _point1MappingToNotUrgent;
        public double Point1MappingToNotUrgent
        {
            get { return _point1MappingToNotUrgent; }
            set
            {
                if (_point1MappingToNotUrgent == value)
                    return;
                _point1MappingToNotUrgent = value;
                OnPropertyChanged("Point1MappingToNotUrgent");
            }
        }

        private double _point1MappingToUrgent;
        public double Point1MappingToUrgent
        {
            get { return _point1MappingToUrgent; }
            set
            {
                if (_point1MappingToUrgent == value)
                    return;
                _point1MappingToUrgent = value;
                OnPropertyChanged("Point1MappingToUrgent");
            }
        }


        private bool _showDaysSpentForProjectCards;
        public bool ShowDaysSpentForProjectCards
        {
            get { return _showDaysSpentForProjectCards; }
            set
            {
                if (_showDaysSpentForProjectCards == value)
                    return;
                _showDaysSpentForProjectCards = value;
                OnPropertyChanged("ShowDaysSpentForProjectCards");
            }
        }

        private DateTime _iterationEndDate;
        public DateTime IterationEndDate
        {
            get { return _iterationEndDate; }
            set
            {
                if (_iterationEndDate == value)
                    return;
                _iterationEndDate = value;
                OnPropertyChanged("IterationEndDate");
            }
        }


        public void Save()
        {
            _dataService.SaveSettingsAsync(new Settings
                                           {
                                               Point1MappingToNotUrgent = _point1MappingToNotUrgent,
                                               Point1MappingToUrgent = _point1MappingToUrgent,
                                               ShowDaysSpentForProjectCards = _showDaysSpentForProjectCards,
                                               MingleUsername = _mingleUsername,
                                               //MinglePassword = _minglePassword,
                                               MingleStoryUrl = _mingleStoryUrl,
                                               MingleStoryUrlBringAllCardsFromMingle = _mingleStoryUrlBringAllCardsFromMingle,
                                               MingleRegressionUrl = _mingleRegressionUrl,
                                               MingleRegressionUrlBringAllCardsFromMingle = _mingleRegressionUrlBringAllCardsFromMingle,
                                               MingleDPSUrl = _mingleDPSUrl,
                                               MingleDPSUrlBringAllCardsFromMingle = _mingleDPSUrlBringAllCardsFromMingle,
                                               IterationEndDate = _iterationEndDate.ToShortDateString()
                                           });
        }
    }
}